﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace MassIntellect.WorkIt
{
    /// <summary>
    /// Имена классов
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public static class CName<Ttype>
    {
        public static string Name
        {
            get
            {
                return CName.Get(typeof(Ttype)); ;
            }
            set
            {
                CName.AddOrSet(typeof(Ttype), value);
            }
        }
    }

    public class CName : Tags<Type, string>
    {
        public static void Init()
        {
            DefaultTags<Type, string>.GetDefaultFunc += (type) => GetOrSet(type, type.Name);
        }
    }

    public class CXName : Tags<Type, XName>
    {
        public static XName Get<T>()
        {
            return GetOrGen(typeof(T));
        }
        public static void Init()
        {
            DefaultTags<Type, XName>.GetDefaultFunc += (type) => GetOrSet(type, XName.Get(type.Name, XNS.GetOrGen(type).NamespaceName));
        }
    }

    public static class TagsExtension
    {
        public static string GetClassName(this object obj)
        {
            if (obj != null)
                return CName.Get(obj.GetType());
            else
                return string.Empty;
        }
        public static XName GetClassId(this object obj)
        {
            if (obj != null)
                return CXName.Get(obj.GetType());
            else
                return default(XName);
        }
    }
}
